"""
学习路径
"""

from common.models import db
from common.models.base import Base
from common.models.user import UserBase
from common.models.course import Course


class Path(Base):
    """
    学习路径表
    """
    __tablename__ = 'tb_path'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(16), doc='路径名')
    img = db.Column(db.String(256), doc='路径图片')
    desc = db.Column(db.String(256), doc='路径描述')
    user_list = db.relationship('UserBase', secondary='user_path', backref=db.backref('path_list'))


class UserPath(Base):
    """
    用户、学习路径的中间表
    """
    __tablename__ = 'user_path'
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True, doc='用户id')
    path_id = db.Column(db.Integer, db.ForeignKey("tb_path.id"), primary_key=True, doc='路径id')
    is_delete = db.Column(db.Boolean, doc='状态(0存在对应关系;1不存在对应关系)')


class Stage(Base):
    """
    学习阶段
    """
    __tablename__ = 'tb_stage'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(16), doc='阶段名')
    serial_num = db.Column(db.Integer, doc='阶段序号')
    path = db.Column(db.Integer, db.ForeignKey("tb_path.id", ondelete="CASCADE"), doc='学习路径')
    course_list = db.relationship('Course', secondary='course_stage', backref=db.backref('tb_stage'))


class CourseStage(Base):
    """
    课程、学习阶段中间表
    """
    __tablename__ = 'course_stage'
    course = db.Column(db.Integer, db.ForeignKey("tb_course.id"), primary_key=True, doc='课程')
    stage = db.Column(db.Integer, db.ForeignKey("tb_stage.id"), primary_key=True, doc='阶段')
    is_delete = db.Column(db.Boolean, doc='状态(0存在对应关系;1不存在对应关系)')


